package com.java.demo.string;

import java.lang.ref.*;

/**
 * @auther zhangwj
 * @date 2020/4/23 11:04 上午
 */
public class MyReference {

    public static void main(String[] args) throws InterruptedException {


        String a = "2222";
        String b = a;
        a = null;


        String weakStr = "333";
        WeakReference<String> weakReference = new WeakReference<>(weakStr);


        System.out.println("weakStr=" + weakReference.get());


        System.gc();


       while (null != weakReference.get()){

       }
        System.out.println("被回收啦");

        System.out.println("weakStr=" + weakReference.get());


    }

}
